// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-12-20

#include "stdafx.h"
#include "net_monitor.h"

#pragma warning(disable : 4100)

namespace JoyServer
{

CJoyNetMonitor g_netMonitor;

// class CJoyNetMonitor

CJoyNetMonitor::CMonitorData::CMonitorData()
{
    m_transfer  = 0;
    m_operation = 0;
}

void CJoyNetMonitor::CMonitorData::AddOperation(UINT trans)
{
    CJoyAutoCS gate(m_lock);

    m_transfer  += trans;
    m_operation ++;
}

void CJoyNetMonitor::AddSend(SOCKET s, UINT trans)
{
    s;
    m_tcpData.m_send.AddOperation(trans);
}

void CJoyNetMonitor::AddSendTo(SOCKET s, UINT trans)
{
    s;
    m_udpData.m_send.AddOperation(trans);
}

void CJoyNetMonitor::AddRecv(SOCKET s, UINT trans)
{
    s;
    m_tcpData.m_recv.AddOperation(trans);
}

void CJoyNetMonitor::AddRecvFrom(SOCKET s, UINT trans)
{
    s;
    m_udpData.m_recv.AddOperation(trans);
}


/*
DETOUR_TRAMPOLINE(int WINAPI Real_WSASend(SOCKET a0,
                                             LPWSABUF a1,
                                             DWORD a2,
                                             LPDWORD a3,
                                             DWORD a4,
                                             LPWSAOVERLAPPED a5,
                                             LPWSAOVERLAPPED_COMPLETION_ROUTINE a6),
                  WSASend);


DETOUR_TRAMPOLINE(int WINAPI Real_WSASendDisconnect(SOCKET a0,
                                                       LPWSABUF a1),
                  WSASendDisconnect);

DETOUR_TRAMPOLINE(int WINAPI Real_WSASendTo(SOCKET a0,
                                               LPWSABUF a1,
                                               DWORD a2,
                                               LPDWORD a3,
                                               DWORD a4,
                                               sockaddr* a5,
                                               int a6,
                                               LPWSAOVERLAPPED a7,
                                               LPWSAOVERLAPPED_COMPLETION_ROUTINE a8),
                  WSASendTo);

DETOUR_TRAMPOLINE(int WINAPI Real_send(SOCKET a0,
                                          char* a1,
                                          int a2,
                                          int a3),
                  send);

DETOUR_TRAMPOLINE(int WINAPI Real_sendto(SOCKET a0,
                                            char* a1,
                                            int a2,
                                            int a3,
                                            sockaddr* a4,
                                            int a5),
                  sendto);


DETOUR_TRAMPOLINE(int WINAPI Real_WSARecv(SOCKET a0,
                                             LPWSABUF a1,
                                             DWORD a2,
                                             LPDWORD a3,
                                             LPDWORD a4,
                                             LPWSAOVERLAPPED a5,
                                             LPWSAOVERLAPPED_COMPLETION_ROUTINE a6),
                  WSARecv);

DETOUR_TRAMPOLINE(int WINAPI Real_WSARecvDisconnect(SOCKET a0,
                                                       LPWSABUF a1),
                  WSARecvDisconnect);

DETOUR_TRAMPOLINE(int WINAPI Real_WSARecvFrom(SOCKET a0,
                                                 LPWSABUF a1,
                                                 DWORD a2,
                                                 LPDWORD a3,
                                                 LPDWORD a4,
                                                 sockaddr* a5,
                                                 LPINT a6,
                                                 LPWSAOVERLAPPED a7,
                                                 LPWSAOVERLAPPED_COMPLETION_ROUTINE a8),
                  WSARecvFrom);

DETOUR_TRAMPOLINE(int WINAPI Real_recv(SOCKET a0,
                                          char* a1,
                                          int a2,
                                          int a3),
                  recv);

DETOUR_TRAMPOLINE(int WINAPI Real_recvfrom(SOCKET a0,
                                              char* a1,
                                              int a2,
                                              int a3,
                                              sockaddr* a4,
                                              int* a5),
                  recvfrom);


int WINAPI Mine_WSASend(SOCKET a0,
                           LPWSABUF a1,
                           DWORD a2,
                           LPDWORD a3,
                           DWORD a4,
                           LPWSAOVERLAPPED a5,
                           LPWSAOVERLAPPED_COMPLETION_ROUTINE a6)
{
    int rv = 0;
    rv = Real_WSASend(a0, a1, a2, a3, a4, a5, a6);
    if(rv > 0)
    {
    }
    return rv;
}

int WINAPI Mine_WSASendDisconnect(SOCKET a0,
                                     LPWSABUF a1)
{
    int rv = 0;
    rv = Real_WSASendDisconnect(a0, a1);
    return rv;
}

int WINAPI Mine_WSASendTo(SOCKET a0,
                             LPWSABUF a1,
                             DWORD a2,
                             LPDWORD a3,
                             DWORD a4,
                             sockaddr* a5,
                             int a6,
                             LPWSAOVERLAPPED a7,
                             LPWSAOVERLAPPED_COMPLETION_ROUTINE a8)
{
    int rv = 0;
    rv = Real_WSASendTo(a0, a1, a2, a3, a4, a5, a6, a7, a8);
    return rv;
}

int WINAPI Mine_send(SOCKET a0,
                        char* a1,
                        int a2,
                        int a3)
{
    int rv = 0;
    rv = Real_send(a0, a1, a2, a3);
    return rv;
}

int WINAPI Mine_sendto(SOCKET a0,
                          char* a1,
                          int a2,
                          int a3,
                          sockaddr* a4,
                          int a5)
{
    int rv = 0;
    rv = Real_sendto(a0, a1, a2, a3, a4, a5);
    return rv;
}

int WINAPI Mine_WSARecv(SOCKET a0,
                           LPWSABUF a1,
                           DWORD a2,
                           LPDWORD a3,
                           LPDWORD a4,
                           LPWSAOVERLAPPED a5,
                           LPWSAOVERLAPPED_COMPLETION_ROUTINE a6)
{
    int rv = -1;
    rv = Real_WSARecv(a0, a1, a2, a3, a4, a5, a6);
    return rv;
}

int WINAPI Mine_WSARecvDisconnect(SOCKET a0,
                                     LPWSABUF a1)
{
    int rv = 0;
    rv = Real_WSARecvDisconnect(a0, a1);
    return rv;
}

int WINAPI Mine_WSARecvFrom(SOCKET a0,
                               LPWSABUF a1,
                               DWORD a2,
                               LPDWORD a3,
                               LPDWORD a4,
                               sockaddr* a5,
                               LPINT a6,
                               LPWSAOVERLAPPED a7,
                               LPWSAOVERLAPPED_COMPLETION_ROUTINE a8)
{
    int rv = 0;
    rv = Real_WSARecvFrom(a0, a1, a2, a3, a4, a5, a6, a7, a8);
    return rv;
}

int WINAPI Mine_recv(SOCKET a0,
                        char* a1,
                        int a2,
                        int a3)
{
    int rv = 0;
    rv = Real_recv(a0, a1, a2, a3);
    return rv;
}

int WINAPI Mine_recvfrom(SOCKET a0,
                            char* a1,
                            int a2,
                            int a3,
                            sockaddr* a4,
                            int* a5)
{
    int rv = 0;
    rv = Real_recvfrom(a0, a1, a2, a3, a4, a5);
    return rv;
}
*/
} // namespace JoyServer